<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
      <div class="box">
        <h3>小黑自动售货机</h3>
        <button @click="buyOne(5)">可乐5元</button>
        <button @click="buyOne(10)">咖啡10元</button>
      </div>
      <p>银行卡余额：{{money}}元</p>
  </div>

<script src="../js/vue.js"></script>
<script>
 var app = new Vue({
        el: "#app",
        data: {
          money: 100,
        },
        methods:{
          buyOne(sub){
            if(this.money >0 && this.money -sub >= 0){
              this.money -= sub;
            }else{
              alert("余额不足");
            }
            
          }
        }
      });

</script>

<style>
  .box{
    width: 200px;
    height: 200px;
    border: 5px solid black;
    text-align: center;
    padding-top: 80px;
    /* margin: 0 auto; */
  }
</style>
</body>
</html>